<template>
  <div class="app-container">
    <div class="filter-container">
      <span>渠道名称</span>
      <el-input v-model="channels.name" placeholder="渠道名称" style="width: 60%; margin-right: 20px" class="filter-item" />
    </div>
    <div class="filter-container">
      <span>登录用户名</span>
      <el-input
        v-model="channels.username"
        placeholder="登录用户名"
        style="width: 60%; margin-right: 20px"
        class="filter-item"
      />
    </div>
    <div class="filter-container">
      <span>登录密码</span>
      <el-input
        v-model="channels.password"
        placeholder="登录密码"
        style="width: 60%; margin-right: 20px"
        class="filter-item"
      />
    </div>
    <div class="filter-container">
      <span>上级渠道</span>
      <el-select
        v-model="channels.parentId"
        placeholder="请选择"
        clearable
        class="filter-item"
        style="width: 60%; margin-right: 20px"
      >
        <el-option v-for="item in calendarTypeOptions" :key="item.id" :label="item.nickname" :value="item.id" />
      </el-select>
    </div>
    <el-button class="filter-item" type="primary" @click="confirm">
      确认
    </el-button>
  </div>
</template>

<script>
import {
  encryption2
} from '@/api/index'
export default {
  name: 'ComplexTable',
  data() {
    return {
      // 渠道
      channels: {
        name: '', // 名称
        username: '', // 用户名字
        password: '', // 登录密码
        parentId: '' // 上级渠道
      },
      calendarTypeOptions: []
    }
  },
  created() {
    this.Channel()
  },
  methods: {
    Channel() {
      const arys = {
      }
      const url = '/market/singleList'
      encryption2(arys, url).then((res) => {
        if (res.data.status === 0) {
          this.calendarTypeOptions = res.data.result
        } else {
          console.log(res)
        }
      })
    },
    confirm() {
      const arys = {
        name: this.channels.name,
        username: this.channels.username,
        password: this.channels.password,
        parentId: this.channels.parentId ? this.channels.parentId : '0'
      }
      const url = '/market/addMarketAdmin'
      encryption2(arys, url).then((res) => {
        if (res.data.status === 0) {
          this.$message({
            message: res.data.text,
            type: 'success'
          })
          this.$router.go(-1)
        } else {
          this.$message({
            message: res.data.text,
            type: 'error'
          })
        }
      })
    }
  }
}
</script>
<style scoped>
  .filter-container {
    width: 1000px;
    display: flex;
    align-items: center;
  }

  .filter-container>span {
    width: 100px;
    font-size: 16px;
    font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB",
      "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
  }
</style>
